package com.tywj.panda.home.api

import androidx.collection.ArrayMap
import com.tywj.lib.net.retrofit.request.GetRequest
import com.tywj.lib.net.retrofit.request.PostRequest
import com.tywj.navigation.tool.MapTool
import com.tywj.panda.customer.common.api.CommonApi
import com.tywj.panda.customer.common.entity.SelectedPriceDateEntity
import com.tywj.panda.customer.common.manager.AuthorityManager
import com.tywj.panda.customer.common.tool.HttpTool


/**
 * @desc 首页网络请求接口
 * @author June Yang
 * @date 2020/5/18
 */
object HomeApi {


    var GET_LINE_TIME_BY_DATE = CommonApi.API_TICKET_URL + "ticket/line/date/time"

    //GET /ticket/store/list/time 查询班次日历列表
    var GET_DATE_PRICE_BY_DATE = CommonApi.API_TICKET_URL + "ticket/store/list/time"


    private var LINE_LIST = CommonApi.API_ROUTE_URL + "trip/search"

    private var LIST_NOTICE = CommonApi.API_TICKET_URL + "loc/remind/list"
    //是否已读
    private var NOTICE_MODIFY = CommonApi.API_TICKET_URL + "loc/remind/modify"

    //CRM 路线详情
    private var CRM_LINE_DETAILS = CommonApi.API_ROUTE_URL + "trip/detail"

    private var HOME_CITY_LIST = CommonApi.API_TICKET_URL + "ticket/position/city"

    // 生成订单
    private var CREATE_ORDER = CommonApi.API_TICKET_URL + "ticket/order/create"

    //生成预付款信息
    private var PRE_PAYMENT = CommonApi.API_TICKET_URL + "ticket/pay/prepayment/"

    private var LIST_BANNER = CommonApi.API_TICKET_URL + "banner/list"

    //GET /gps/find/route 获取当前线路上所有正在运营的车辆位
    private var FIND_ROUTE = CommonApi.API_ROUTE_URL + "gps/find/route"

    fun listLines(): GetRequest {
        return HttpTool.get(LINE_LIST)
    }


    /**
     * 获取首页（搜索）的全部参数
     * @param cityCode 城市ID
     * @param type 1 -系统 2 用户
     * @param startLng 出发经度
     * @param startLat 出发纬度
     * @param endLng 终点经度
     * @param endLat 终点纬度
     */
    fun getBusLines(
        cityCode: String = MapTool.CITY_CODE,
        type: Int = 1,
        startLng: Double = 0.0,
        startLat: Double = 0.0,
        endLng: Double = 0.0,
        endLat: Double = 0.0,
        offset: String = "1",
        limit: String = "10"
    ): GetRequest {
        return HttpTool.get(LINE_LIST)
            .param("city_code", cityCode)
            .param("type", type.toString())
            .param("s_lng", startLng.toString())
            .param("s_lat", startLat.toString())
            .param("e_lng", endLng.toString())
            .param("e_lat", endLat.toString())
            .param("offset", offset)
            .param("limit", limit)
    }

    /**
     * 获取首页（搜索）的全部参数map
     * @param cityCode 城市ID
     * @param type 1 -系统 2 用户
     * @param startLng 出发经度
     * @param startLat 出发纬度
     * @param endLng 终点经度
     * @param endLat 终点纬度
     */
    fun listLinesAllParams(
        filterParams: ArrayMap<String, String>,
        cityCode: Int = 0,
        type: String = "1",
        startLng: Double = 0.0,
        startLat: Double = 0.0,
        endLng: Double = 0.0,
        endLat: Double = 0.0,
        offset: String = "",
        limit: String = ""

    ): ArrayMap<String, String> {
        filterParams["city_code"] = "0"
        filterParams["type"] = type
        filterParams["s_lng"] = startLng.toString()
        filterParams["s_lat"] = startLat.toString()
        filterParams["e_lng"] = endLng.toString()
        filterParams["e_lat"] = endLat.toString()

        filterParams["offset"] = "1"
        filterParams["limit"] = "10"
        return filterParams
    }


    fun getCRMLineDetails(id: String): GetRequest {
        return HttpTool.get(CRM_LINE_DETAILS).param("line_info_id", id)
    }

    //获取站点时间
    fun getLineTimeByDate(lineCode: String): GetRequest {
        return HttpTool.get(GET_LINE_TIME_BY_DATE).param("line_code", lineCode)
    }

    //根据时间获取日历价格信息
    fun getDatePriceByTime(lineCode: String, lineTime: String): GetRequest {
        return HttpTool.get(GET_DATE_PRICE_BY_DATE)
            .param("line_code", lineCode)
            .param("line_time", lineTime)
    }

    /**
     * 获取通知列表
     */

    fun listNoticeParams(createDate: Long = 0L): ArrayMap<String, String> {
        val map = ArrayMap<String, String>()
        map["uid"] = AuthorityManager.uid
        if (createDate == 0L) {
            map["create_date"] = System.currentTimeMillis().toString()
        } else {
            map["create_date"] = createDate.toString()
        }
        map["page_size"] = "10" //分页大小
        map["page_type"] = "1" ////1:当前时间之前(下一页) 2:当前时间之后（上一页)

        return map
    }

    fun listNotice(): GetRequest = HttpTool.get(LIST_NOTICE)

    fun homeNotice(): GetRequest = HttpTool.get(LIST_NOTICE).param("create_date", System.currentTimeMillis().toString())
        .param("page_size", "10").param("page_type", "1")
        .param("uid", AuthorityManager.uid)

    /**
     * 本地消息更新已读
     * @param read 1已读 0 未读
     */
    fun readNotice(id: String): PostRequest =
        HttpTool.post(NOTICE_MODIFY).param("id", id)


    /**
     * @param cityName 城市名称
     * @param startStation 上车地点
     * @param endStation 下车地点
     * @param endStation 下车地点
     * @param lineTime 发车时间
     * @param lineName 线路名称
     * @param money 合计金额
     *
     */
    fun createOrder(
        cityName: String = MapTool.CITY_DEFAULT,
        startStation: String,
        endStation: String,
        onTime: String = "",
        offTime: String = "",
        LineCode: String,
        lineTime: String,
        lineName: String,
        goodsList: ArrayList<SelectedPriceDateEntity>,
        number: Int,
        money: Int
    ): PostRequest {
        return HttpTool.post(CREATE_ORDER)
            .param("city_name", cityName)
            .param("getoff_loc", endStation)
            .param("geton_loc", startStation)

            .param("geton_time", onTime)
            .param("getoff_time", offTime)

            .param("line_code", LineCode)
            .param("line_time", lineTime)
            .param("line_name", lineName)

            .param("goods", goodsList)
            .param("number", number) //数量
            .param("money", money) //总价 =数量*销售价

    }

    /**
     * 生成预付款信息
     * @param orderNo 订单号
     * @param payMode 支付方式, alipay, wxpay
     */
    fun prepayment(orderNo: String, payMode: String): PostRequest {
        return HttpTool.post(PRE_PAYMENT)
            .param("order_no", orderNo)
            .param("pay_mode", payMode)
    }

    /**
     * 类型 1:启动类型 2：首页类型
     * @param type
     */
    fun listBanner(type: Int = 2): GetRequest {
        return HttpTool.get(LIST_BANNER).param("banner_type", type.toString())
    }

    fun getGpsRoute(lineCode: String): GetRequest {
        return HttpTool.get(FIND_ROUTE).param("line_code", lineCode)
    }
}